/*
 *  Ch2.h
 *  UnixSysPro
 *
 *  Created by 黄 鑫 on 07-8-20.
 *  Copyright 2007 __MyCompanyName__. All rights reserved.
 *
 */

#include <Carbon/Carbon.h>

#include <fcntl.h>

int filestatus (int filedes)
{
	int arg1;
	
	if ((arg1 = fcntl(filedes,F_GETFL))== -1)
	{
		printf("filestatus failed \n");
		return (-1);
	}
	printf("File descriptor %d",filedes);
	
	/*test the argument against the open flags*/
	
	switch(arg1&O_ACCMODE){
	case O_WRONLY:
				printf("write-only");
				break;
	case O_RDWR:
				printf("read-write");
				break;
	case O_RDONLY:
				printf("read-only");
	default:
				print("No such mode");
	}
	
	if (arg1 & O_APPEND)
		printf("-append flag set");
		
	printf("\n");
	return (0);
}


